"""
@File         : validate.py
@Time         : 2024/05/06 15:56:17
@Author       : Qrj
@Email        : 923207736@qq.com
@Description  : 通知公告的验证模型
"""

from datetime import datetime

from pydantic import BaseModel, Field, conint

from src.business.admin.system.notice.enums import NoticeTypeEnum
from src.schemas.validate import (
    BaseSearchValidateSchemaMixin,
    BaseValidateSchemaConfigMixin,
)


class NoticeCreateValidateSchema(BaseModel, BaseValidateSchemaConfigMixin):
    """用于创建通知公告的验证模型"""

    title: str = Field(default=..., min_length=1, max_length=50, description="公告标题")
    content: str = Field(default=..., min_length=1, description="公告内容")
    notice_type: NoticeTypeEnum = Field(
        default=NoticeTypeEnum.background_notice.value, description="通知公告类型"
    )
    status: bool = Field(default=True, description="状态")  # (True正常 False停用)
    show_order: int = Field(
        default=1, min_length=1, max_length=999999999, description="显示顺序"
    )
    expiration_datetime: datetime = Field(default=..., description="过期时间")


class NoticeUpdateValidateSchema(BaseModel, BaseValidateSchemaConfigMixin):
    """用于修改通知公告的验证模型"""

    id: int = Field(default=..., ge=1, description="主键")
    title: str = Field(default=..., min_length=1, max_length=50, description="公告标题")
    content: str = Field(default=..., min_length=1, description="公告内容")
    notice_type: NoticeTypeEnum = Field(
        default=NoticeTypeEnum.background_notice.value, description="通知公告类型"
    )
    status: bool = Field(default=True, description="状态")  # (True正常 False停用)
    show_order: int = Field(
        default=1, min_length=1, max_length=999999999, description="显示顺序"
    )
    expiration_datetime: datetime = Field(default=..., description="过期时间")


class NoticeUpdateStatusValidateSchema(BaseModel, BaseValidateSchemaConfigMixin):
    """用于单独修改通知公告状态的验证模型"""

    id: int = Field(default=..., ge=1, description="主键")
    status: bool = Field(default=..., description="状态")  # (True正常 False停用)


class NoticeDeleteValidateSchema(BaseModel, BaseValidateSchemaConfigMixin):
    """用于删除通知公告的验证模型"""

    ids: list[conint(ge=1)] = Field(
        default=..., min_length=1, description="需删除的主键列表"
    )


class NoticeListSearchValidateSchema(BaseModel, BaseSearchValidateSchemaMixin):
    """用于查询通知公告列表的验证模型"""

    title: str | None = Field(
        default=None,
        min_length=1,
        max_length=50,
        description="公告标题",
        json_schema_extra={"str_like_search_type": "complete"},
    )
    content: str | None = Field(
        default=None,
        description="公告内容",
        min_length=1,
        max_length=1000,
        json_schema_extra={"str_like_search_type": "complete"},
    )
    notice_type: NoticeTypeEnum | None = Field(default=None, description="通知公告类型")
    status: bool | None = Field(default=None, description="状态")
    expiration_datetime: tuple[datetime, datetime] | None = Field(
        default=None,
        description="过期时间",
        json_schema_extra={"allow_order": True},
    )
    create_datetime: tuple[datetime, datetime] | None = Field(
        default=None,
        description="创建时间",
        json_schema_extra={"allow_order": True},
    )
    update_datetime: tuple[datetime, datetime] | None = Field(
        default=None,
        description="修改时间",
        json_schema_extra={"allow_order": True},
    )
    creator_username: str | None = Field(
        default=None,
        min_length=1,
        max_length=20,
        description="创建者用户名",
        json_schema_extra={"str_like_search_type": "complete"},
    )
    updater_username: str | None = Field(
        default=None,
        min_length=1,
        max_length=20,
        description="修改者用户名",
        json_schema_extra={"str_like_search_type": "complete"},
    )
